/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;
import models.Docente;
import models.Plantilla_Base;
import play.libs.*;
import play.cache.*;

/**
 *
 * @author Administrador
 */
public class Security extends Secure.Security{
    
    static boolean authenticate(String username, String password, String code) {
        //Docentes de prueba
//        new Docente("000001", "1", "Victor Hugo", "Bustamante", "Olivera", "44444444", "Av. Universitaria S/N", "correo1@hotmail.com", "correo2@hotmail.com", "correo3@hotmail.com", "3333333", "5555555","7777777","Asociado","Tiempo Parcial","C. Computacion").save();
//        new Docente("000002", "2", "Jorge", "Chavez", "Soto", "22222222", "Av. La Marina S/N", "correo1@hotmail.com", "correo2@hotmail.com", "correo3@hotmail.com","5555555","7777777","9999999","Asociado","Tiempo Parcial","C. Computacion").save();
//        new Docente("000000", "0", "Jefe Dpto Acad", "", "", "44444444", "Av. Universitaria S/N", "correo1@hotmail.com", "correo2@hotmail.com", "correo3@hotmail.com", "3333333", "5555555","7777777","Asociado","Tiempo Parcial","C. Computacion").save();
//        new Docente("999999", "9", "Decano", "", "", "22222222", "Av. La Marina S/N", "correo1@hotmail.com", "correo2@hotmail.com", "correo3@hotmail.com","5555555","7777777","9999999","Asociado","Tiempo Parcial","C. Computacion").save();
//        if(Plantilla_Base.findAll().isEmpty())
//            crearPlantilla();
        
        System.out.println("\nAutenticando...");
        System.out.println("code " + code);
        return Docente.connect(username, password) != null;
    }
    
    private static void crearPlantilla(){
        for (int i = 0; i < 7; i++) {
            new Plantilla_Base(i).save();
            
        }
    }
    
    public static void captcha(String id) {
        Images.Captcha captcha = Images.captcha();
        String code = captcha.getText("#000000");
        Cache.set(id, code, "10mn");
        renderBinary(captcha);
    }
}
